﻿using UnityEngine;
using System.Collections;

public class FX_move_loop : MonoBehaviour {

	public bool loop = false;
	public Vector3 vPositionValue = new Vector3 (0, 0, 0);
	
	public float duration = 1.0f;
	
	Vector3 vOriginalPos;
	float timer = 0;
	
	[SerializeField]
	AnimationCurve curveX;
	[SerializeField]
	AnimationCurve curveY;
	[SerializeField]
	AnimationCurve curveZ;
	
	
	void Start(){
		vOriginalPos = transform.localPosition;
	}
	
	void Update ()
	{
		
		Vector3 localPosition = transform.localPosition;
		localPosition.x = curveX.Evaluate(timer)* vPositionValue.x;
		localPosition.y = curveY.Evaluate(timer)* vPositionValue.y;
		localPosition.z = curveZ.Evaluate(timer)* vPositionValue.z;
		transform.localPosition = localPosition + vOriginalPos;
		
		timer += Time.deltaTime/duration;

		if (loop) {
			if(timer >= 1.0f){
				timer = 0f;
			}
		}
	}
}
